﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{
    public partial class ScanMAWB : Form
    {
        WebPor.Service1 lc = new WebPor.Service1();
        bool mes = false;
        string mawb_no, userid = String.Empty;

        DataSet data = new DataSet();
        public ScanMAWB(string user)
        {
            InitializeComponent();
            this.userid = user;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {

            Form1 menu = new Form1(userid);
            menu.Show();
            this.Close();

        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            ScanMAWB_func();
        }

        string mawb_local = "";
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            vadidation_length_func();

        }

        private string InsertdetTodigit(string mawb_local)
        {
            string mawbfull = "";
            string f = mawb_local;
            string p = "";
            string s = "";
            if (mawb_local.Length == 11)
            {
                p = f.Substring(0, 3);
                s = f.Substring(3, f.Length - p.Length);

                return mawbfull = p + "-" + s;
            }
            return "";

        }







        //Rong









        private void ScanMAWB_func()
        {

            int count_mawb_no = 1;

            lc.Url = String.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");


            //Retrieve T/S Cargo Spot
            mes = lc.usp_HHTGetMAWB(mawb_local, userid);


            if (mes == false)              // valid MAWB
            {
                label2.Visible = true;
                label2.Text = "Invalid MAWB";


            }
            else
            {

                count_mawb_no = lc.GetcountMAWB(mawb_no); //  call service get count mawb   
                if (count_mawb_no > 1)       // check only 1 MAWB 
                {                            //  case  MAWB > 1
                    //data = lc.Getdata(mawb_no);
                    Store_Cargo.MAWBSelect MS = new DEMO_TEMP1.Store_Cargo.MAWBSelect(userid, mawb_no);
                    MS.Show();
                    this.Close();
                }
                else
                {                           // case MAWB = 1
                    //data = lc.Getdata(mawb_no);
                    Scanlocation scanloc = new Scanlocation(userid, mawb_no, 0);
                    scanloc.Show();
                    this.Close();
                }

            }
        }



        private void vadidation_length_func()
        {

            mawb_local = textBox1.Text.Trim();

            if (mawb_local.Length == 11 || mawb_local.Length == 16)
            {

                mawb_no = InsertdetTodigit(mawb_local);

            }

        }
    
   
    
    
    }
}